﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jzgl
{
    public partial class AdminWindow : Form
    {
        FlowLayoutPanel[] FLP = new FlowLayoutPanel[3];
        const int Temp = 10;
        Panel[] PA = new Panel[Temp];
        public AdminWindow()
        {
            InitializeComponent();
            FLP[0] = CXPanel;
            FLP[1] = FDPanel;
            FLP[2] = SWPanel;
            PA[0] = panel1;
            PA[1] = panel2;
            PA[2] = panel3;
            PA[3] = panel4;
            PA[4] = panel5;
            PA[5] = panel6;
            PA[6] = panel7;
            PA[7] = panel8;
            PA[8] = panel9;
            PA[9] = panel10;
        }
        private void ReVisible(object sender,EventArgs e,int k)//关闭非当前容器方法
        {
            for (int i = 0; i < Temp; i++)
            {
                if (PA[i].Name != "panel"+ k.ToString() )
                    PA[i].Visible = false;
            }
        }
        private void CXButton_Click(object sender, EventArgs e)//导航栏---信息查询按钮
        {
            CXPanel.Visible = !CXPanel.Visible;
            for (int i = 0; i < 3; i++)
            {
                if (FLP[i].Name != "CXPanel")
                    FLP[i].Visible = false;
            }
        }
        private void FDButton_Click(object sender, EventArgs e)//导航栏---罚单管理
        {
            FDPanel.Visible = !FDPanel.Visible;
            for (int i = 0; i < 3; i++)
            {
                if (FLP[i].Name != "FDPanel")
                    FLP[i].Visible = false;
            }
        }
        private void SWButton_Click(object sender, EventArgs e)//导航栏---事物办理
        {
            SWPanel.Visible = !SWPanel.Visible;
            for (int i = 0; i < 3; i++)
            {
                if (FLP[i].Name != "SWPanel")
                    FLP[i].Visible = false;
            }
        }
        private void RestartButton_Click(object sender, EventArgs e)//注销按钮
        {
            Application.Restart();
        }
        private void ExitButton_Click(object sender, EventArgs e)//退出按钮
        {
            DialogResult dr = MessageBox.Show("确定要退出？", "退出", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                Application.Exit();
            }
        }
        private void PersonButton_Click(object sender, EventArgs e)//信息查询---个人信息
        {
            ReVisible(sender,e,1);
            panel1.Visible = true;
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var result = from L in DB.License
                            select new
                            {
                                姓名 = L.NAME,
                                驾照编号 = L.LICENSENUM,
                                驾照类型 = L.TYPE,
                                初次领证日期 = L.FIRSTDATE,
                                有效期限 = L.EXDATE,
                                记分情况 = L.MARKS.ToString() + "/12",
                                激活状态 = L.STATE == 1 ? "可用" : "不可用"
                            };
            dataGridView1.DataSource = result;
        }
        private void radioChange(object sender, EventArgs e)//信息查询---个人信息--按是否激活查询
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            IQueryable result;
            if (radioButton1.Checked == true)
            {
                result = from L in DB.License
                         where L.STATE == 1
                         select new
                         {
                             姓名 = L.NAME,
                             驾照编号 = L.LICENSENUM,
                             驾照类型 = L.TYPE,
                             初次领证日期 = L.FIRSTDATE,
                             有效期限 = L.EXDATE,
                             记分情况 = L.MARKS.ToString() + "/12",
                             激活状态 = L.STATE == 1 ? "可用" : "不可用"
                         };
            }
            else if (radioButton2.Checked == true)
            {
                result = from L in DB.License
                         where L.STATE == 0
                         select new
                         {
                             姓名 = L.NAME,
                             驾照编号 = L.LICENSENUM,
                             驾照类型 = L.TYPE,
                             初次领证日期 = L.FIRSTDATE,
                             有效期限 = L.EXDATE,
                             记分情况 = L.MARKS.ToString() + "/12",
                             激活状态 = L.STATE == 1 ? "可用" : "不可用"
                         };
            }
            else
            {
                result = from L in DB.License
                         select new
                         {
                             姓名 = L.NAME,
                             驾照编号 = L.LICENSENUM,
                             驾照类型 = L.TYPE,
                             初次领证日期 = L.FIRSTDATE,
                             有效期限 = L.EXDATE,
                             记分情况 = L.MARKS.ToString() + "/12",
                             激活状态 = L.STATE == 1 ? "可用" : "不可用"
                         };
            }
            dataGridView1.DataSource = result;
        }
        private void radioButton1_CheckedChanged(object sender, EventArgs e)//信息查询---单选框发生改变后的转向
        {
            radioChange(sender, e);
        }
        private void radioButton2_CheckedChanged(object sender, EventArgs e)//信息查询---单选框发生改变后的转向
        {
            radioChange(sender, e);
        }
        private void radioButton3_CheckedChanged(object sender, EventArgs e)//信息查询---单选框发生改变后的转向
        {
            radioChange(sender, e);
        }
        private void CXbutton2_Click(object sender, EventArgs e)//信息查询---个人信息--根据驾照编号查询
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            try { int.Parse(textBox2.Text); }
            catch { MessageBox.Show("请输入数字"); }
            if (textBox2.Text != null)
            {
                var result = from L in DB.License
                             where L.LICENSENUM.ToString().Equals(textBox2.Text)
                             select new
                             {
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM,
                                 驾照类型 = L.TYPE,
                                 初次领证日期 = L.FIRSTDATE,
                                 有效期限 = L.EXDATE,
                                 记分情况 = L.MARKS.ToString() + "/12",
                                 激活状态 = L.STATE == 1 ? "可用" : "不可用"
                             };
                dataGridView1.DataSource = result;
            }
            else
            {
                var result = from L in DB.License
                             select new
                             {
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM,
                                 驾照类型 = L.TYPE,
                                 初次领证日期 = L.FIRSTDATE,
                                 有效期限 = L.EXDATE,
                                 记分情况 = L.MARKS.ToString() + "/12",
                                 激活状态 = L.STATE == 1 ? "可用" : "不可用"
                             };
                dataGridView1.DataSource = result;
            }
        }
        private void textBox2_TextChanged(object sender, EventArgs e)//信息查询---个人信息--编号查询输入控制
        {
            if (textBox2.Text.Length == 8)
            {
                CXbutton2.Enabled = true;
            }
            else
            {
                CXbutton2.Enabled = false;
            }
        }
        private void CZbutton_Click(object sender, EventArgs e)//信息查询---个人信息--重置按钮
        {
            textBox1.Text = null;
            textBox2.Text = null;
            radioButton3.Checked = true;
        }
        private void CXbutton1_Click(object sender, EventArgs e)//信息查询---个人信息--根据领证年份查询
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            try { int.Parse(textBox1.Text); }
            catch { MessageBox.Show("请输入数字"); }
            if (textBox2.Text != null)
            {
                var result = from L in DB.License
                             where L.FIRSTDATE.ToString().Substring(0,4).Equals(textBox1.Text)
                             select new
                             {
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM,
                                 驾照类型 = L.TYPE,
                                 初次领证日期 = L.FIRSTDATE,
                                 有效期限 = L.EXDATE,
                                 记分情况 = L.MARKS.ToString() + "/12",
                                 激活状态 = L.STATE == 1 ? "可用" : "不可用"
                             };
                dataGridView1.DataSource = result;
            }
            else
            {
                var result = from L in DB.License
                             select new
                             {
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM,
                                 驾照类型 = L.TYPE,
                                 初次领证日期 = L.FIRSTDATE,
                                 有效期限 = L.EXDATE,
                                 记分情况 = L.MARKS.ToString() + "/12",
                                 激活状态 = L.STATE == 1 ? "可用" : "不可用"
                             };
                dataGridView1.DataSource = result;
            }
        }
        private void KFButton_Click(object sender, EventArgs e)//信息查询---扣分查询
        {
            var Lid = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            DataClasses1DataContext DB = new DataClasses1DataContext();
            ReVisible(sender, e, 2);
            panel2.Visible = true;
            var result = from L in DB.License
                          where L.LICENSENUM.ToString().Equals(Lid)
                          select new
                          {
                              姓名 = L.NAME,
                              驾照编号 = L.LICENSENUM,
                              驾照类型 = L.TYPE,
                              初次领证日期 = L.FIRSTDATE,
                              有效期限 = L.EXDATE,
                              记分情况 = L.MARKS.ToString() + "/12",
                              激活状态 = L.STATE == 1 ? "可用" : "不可用"
                          };
            dataGridView2.DataSource = result;
            var result2 = from A in DB.License
                         join B in DB.Ticket on A.LICENSENUM equals B.LICENSENUM
                         join C in DB.Illegal on B.CODE equals C.CODE
                         where A.LICENSENUM.ToString().Equals(Lid)
                         select new
                         {
                             罚单编号 = B.ID,
                             时间 = B.TIME,
                             地点 = B.PLACE,
                             违章内容 = C.CONTENTS,
                             扣分 = C.DECMARKS
                         };            
            dataGridView3.DataSource = result2;
        }
        private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)//信息查询---修改按钮激活
        {
            if (dataGridView1.CurrentCell != null)
            {
                KFButton.Enabled = true;
                XGButton.Enabled = true;
            }
        }
        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)//信息查询---双击转向
        {
            KFButton_Click(sender, e);
        }
        private void addButton_Click(object sender, EventArgs e)//信息查询---信息添加 
        {
            ReVisible(sender, e, 3);
            panel3.Visible = true;      
        }
        private bool FormatJudge(TextBox t, String s)//判断格式方法
        {
            try { int.Parse(t.Text); return true; }
            catch { MessageBox.Show(s); return false; }
        }
        private void addbutton1_Click(object sender, EventArgs e)//信息查询---信息添加--添加操作
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            if (!string.IsNullOrWhiteSpace(NametextBox.Text) && !string.IsNullOrWhiteSpace(LidtextBox.Text)
                && !string.IsNullOrWhiteSpace(TypetextBox.Text) && !string.IsNullOrWhiteSpace(dateTimePicker1.Text))
            {
                if (FormatJudge(LidtextBox, "驾照格式不正确（8位纯数字）"))
                {
                    License l1 = DB.License.SingleOrDefault(p => p.LICENSENUM == int.Parse(LidtextBox.Text));
                    if (l1 != null)
                    {
                        MessageBox.Show("驾照已存在");
                    }
                    else
                    {
                        License li = new License()
                        {
                            NAME = NametextBox.Text,
                            LICENSENUM = int.Parse(LidtextBox.Text),
                            TYPE = TypetextBox.Text,
                            FIRSTDATE = DateTime.Parse(dateTimePicker1.Text),
                            EXDATE = DateTime.Parse(dateTimePicker1.Text).AddYears(10),
                            MARKS = 12,
                            STATE = 1
                        };
                        DB.License.InsertOnSubmit(li);
                        DB.SubmitChanges();
                        MessageBox.Show("添加完成");
                    }
                }
            }
            else { MessageBox.Show( "请填写完整"); }             
        }
        private void XGButton_Click(object sender, EventArgs e)//信息查询---信息修改
        {
            ReVisible(sender, e, 4);
            panel4.Visible = true;
            var Lid = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var Lp = DB.License.Single(p => p.LICENSENUM.ToString().Equals(Lid));
            var result = from L in DB.License
                         where L.LICENSENUM.ToString().Equals(Lid)
                         select new
                         {
                             姓名 = L.NAME,
                             驾照编号 = L.LICENSENUM,
                             驾照类型 = L.TYPE,
                             初次领证日期 = L.FIRSTDATE,
                             有效期限 = L.EXDATE,
                             记分情况 = L.MARKS.ToString() + "/12",
                             激活状态 = L.STATE == 1 ? "可用" : "不可用"
                         };
            dataGridView4.DataSource = result;
            nametextBox1.Text = dataGridView4.SelectedRows[0].Cells[0].Value.ToString();
            lidtextBox1.Text = dataGridView4.SelectedRows[0].Cells[1].Value.ToString();
            typetextBox1.Text = dataGridView4.SelectedRows[0].Cells[2].Value.ToString();
            dateTimePicker2.Value = DateTime.Parse(dataGridView4.SelectedRows[0].Cells[3].Value.ToString());
        }
        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)//信息查询---信息修改--日期控制
        {
            dateTimePicker3.Value = dateTimePicker2.Value.AddYears(10);
        }
        private void xgbutton1_Click(object sender, EventArgs e)//信息查询---信息修改--修改操作
        {
            var Lid = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var Lp = DB.License.Single(p => p.LICENSENUM.ToString().Equals(Lid));
            DialogResult dr = MessageBox.Show("确定要修改吗？", "取消", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                Lp.NAME = nametextBox1.Text;
                Lp.LICENSENUM = int.Parse(lidtextBox1.Text);
                Lp.TYPE = typetextBox1.Text;
                Lp.FIRSTDATE = dateTimePicker2.Value;
                Lp.EXDATE = dateTimePicker3.Value;
                DB.SubmitChanges();
                MessageBox.Show("修改完成");
                XGButton_Click(sender, e);
            }
        }
        private void button1_Click(object sender, EventArgs e)//信息查询---信息修改--重置按钮
        {
            XGButton_Click(sender, e);
        }
        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)//信息查询---信息添加--日期控制
        {
            dateTimePicker4.Value = dateTimePicker1.Value.AddYears(10);
        }
        private void toolStripMenuItem1_Click(object sender, EventArgs e)//信息查询---个人信息--右键扣分
        {
            KFButton_Click(sender, e);
        }
        private void toolStripMenuItem2_Click(object sender, EventArgs e)//信息查询---个人信息--右键修改
        {
            XGButton_Click(sender, e);
        }
        private void toolStripMenuItem3_Click(object sender, EventArgs e)//信息查询---个人信息--右键罚单添加
        {
            FDJFButton_Click(sender, e);
            FDTJtextBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
        }
        private void FDCXButton_Click(object sender, EventArgs e)//罚单管理---罚单查询
        {
            ReVisible(sender,e,5);
            panel5.Visible = true;
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var result = from L in DB.License
                         join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                         join I in DB.Illegal on T.CODE equals I.CODE 
                         select new
                         {
                             罚单编号 = T.ID,                                                          
                             违章内容 = I.CONTENTS,
                             违章时间 = T.TIME,
                             违章地点 = T.PLACE,
                             缴费期限 = T.EXDATE,
                             缴费情况 = T.STATE == 1 ? "已缴费" : "未缴费",
                             姓名 = L.NAME,
                             驾照编号 = L.LICENSENUM
                         };
            dataGridView5.DataSource = result;
        }
        private void radioChange2(object sender, EventArgs e)//罚单管理---罚单查询--按是否缴费查询
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            IQueryable result;
            if (radioButton6.Checked == true)
            {
                result = from L in DB.License
                         join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                         join I in DB.Illegal on T.CODE equals I.CODE
                         where T.STATE == 1
                         select new
                         {
                             罚单编号 = T.ID,
                             违章内容 = I.CONTENTS,
                             违章时间 = T.TIME,
                             违章地点 = T.PLACE,
                             缴费期限 = T.EXDATE,
                             缴费情况 = T.STATE == 1 ? "已缴费" : "未缴费",
                             姓名 = L.NAME,
                             驾照编号 = L.LICENSENUM
                         };
            }
            else if (radioButton5.Checked == true)
            {
                result = from L in DB.License
                         join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                         join I in DB.Illegal on T.CODE equals I.CODE
                         where T.STATE == 0
                         select new
                         {
                             罚单编号 = T.ID,
                             违章内容 = I.CONTENTS,
                             违章时间 = T.TIME,
                             违章地点 = T.PLACE,
                             缴费期限 = T.EXDATE,
                             缴费情况 = T.STATE == 1 ? "已缴费":"未缴费",
                             姓名 = L.NAME,
                             驾照编号 = L.LICENSENUM
                         };
            }
            else
            {
                result = from L in DB.License
                        join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                        join I in DB.Illegal on T.CODE equals I.CODE
                        select new
                        {
                            罚单编号 = T.ID,
                            违章内容 = I.CONTENTS,
                            违章时间 = T.TIME,
                            违章地点 = T.PLACE,
                            缴费期限 = T.EXDATE,
                            缴费情况 = T.STATE == 1 ? "已缴费":"未缴费",
                            姓名 = L.NAME,
                            驾照编号 = L.LICENSENUM
                        };
            }
            dataGridView5.DataSource = result;
        }
        private void radioButton4_CheckedChanged(object sender, EventArgs e)//罚单管理---罚单查询--单选框发生改变后的转向
        {
            radioChange2(sender, e);
        }
        private void radioButton5_CheckedChanged(object sender, EventArgs e)//罚单管理---罚单查询--单选框发生改变后的转向
        {
            radioChange2(sender, e);
        }
        private void radioButton6_CheckedChanged(object sender, EventArgs e)//罚单管理---罚单查询--单选框发生改变后的转向
        {
            radioChange2(sender, e);
        }
        private void fdcxbutton1_Click(object sender, EventArgs e)//罚单管理---罚单查询--根据罚单编号查询
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            try { int.Parse(textBox3.Text); }
            catch { MessageBox.Show("请输入数字"); }
            if (textBox3.Text != null)
            {
                var result = from L in DB.License
                             join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                             join I in DB.Illegal on T.CODE equals I.CODE
                             where T.ID.ToString().Equals(textBox3.Text)
                             select new
                             {
                                 罚单编号 = T.ID,
                                 违章内容 = I.CONTENTS,
                                 违章时间 = T.TIME,
                                 违章地点 = T.PLACE,
                                 缴费期限 = T.EXDATE,
                                 缴费情况 = T.STATE == 1 ? "已缴费" : "未缴费",
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM
                             };
                dataGridView5.DataSource = result;
            }
            else
            {
                var result = from L in DB.License
                             join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                             join I in DB.Illegal on T.CODE equals I.CODE
                             select new
                             {
                                 罚单编号 = T.ID,
                                 违章内容 = I.CONTENTS,
                                 违章时间 = T.TIME,
                                 违章地点 = T.PLACE,
                                 缴费期限 = T.EXDATE,
                                 缴费情况 = T.STATE == 1 ? "已缴费" : "未缴费",
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM
                             };
                dataGridView5.DataSource = result;
            }
        }
        private void textBox3_TextChanged(object sender, EventArgs e)//罚单管理---罚单查询--编号查询输入控制
        {
            if (textBox3.Text.Length == 8)
            {
                fdcxbutton1.Enabled = true;
            }
            else
            {
                fdcxbutton1.Enabled = false;
            }
        }
        private void fdcxbutton2_Click(object sender, EventArgs e)//罚单管理---罚单查询--根据驾照编号查询
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            try { int.Parse(textBox4.Text); }
            catch { MessageBox.Show("请输入数字"); }
            if (textBox4.Text != null)
            {
                var result = from L in DB.License
                             join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                             join I in DB.Illegal on T.CODE equals I.CODE
                             where T.LICENSENUM.ToString().Equals(textBox4.Text)
                             select new
                             {
                                 罚单编号 = T.ID,
                                 违章内容 = I.CONTENTS,
                                 违章时间 = T.TIME,
                                 违章地点 = T.PLACE,
                                 缴费期限 = T.EXDATE,
                                 缴费情况 = T.STATE == 1 ? "已缴费" : "未缴费",
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM
                             };
                dataGridView5.DataSource = result;
            }
            else
            {
                var result = from L in DB.License
                             join T in DB.Ticket on L.LICENSENUM equals T.LICENSENUM
                             join I in DB.Illegal on T.CODE equals I.CODE
                             select new
                             {
                                 罚单编号 = T.ID,
                                 违章内容 = I.CONTENTS,
                                 违章时间 = T.TIME,
                                 违章地点 = T.PLACE,
                                 缴费期限 = T.EXDATE,
                                 缴费情况 = T.STATE == 1 ? "已缴费" : "未缴费",
                                 姓名 = L.NAME,
                                 驾照编号 = L.LICENSENUM
                             };
                dataGridView5.DataSource = result;
            }
        }
        private void textBox4_TextChanged(object sender, EventArgs e)//罚单管理---罚单查询--驾照查询输入控制
        {
            if (textBox4.Text.Length == 8)
            {
                fdcxbutton2.Enabled = true;
            }
            else
            {
                fdcxbutton2.Enabled = false;
            }
        }
        private void button2_Click(object sender, EventArgs e)//罚单管理---罚单查询--重置按钮
        {
            textBox3.Text = null;
            textBox4.Text = null;
            radioButton4.Checked = true;
        }
        private void AdminWindow_Load(object sender, EventArgs e)
        {
            // TODO:  这行代码将数据加载到表“jZGLDataSet.Illegal”中。您可以根据需要移动或删除它。
            this.illegalTableAdapter.Fill(this.jZGLDataSet.Illegal);

        }
        private void FDJFButton_Click(object sender, EventArgs e)//罚单管理---罚单添加
        {
            ReVisible(sender, e, 6);
            panel6.Visible = true;     
        }
        private void button4_Click(object sender, EventArgs e)//罚单管理---罚单添加--添加操作
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            if (!string.IsNullOrWhiteSpace(FDTJtextBox2.Text) && !string.IsNullOrWhiteSpace(FDTJtextBox3.Text))
            {
                if (FormatJudge(FDTJtextBox2, "驾照格式不正确（8位纯数字）"))
                {
                    License l1 = DB.License.SingleOrDefault(p => p.LICENSENUM.ToString().Equals(FDTJtextBox2.Text));
                    if (l1 == null)
                    {
                        MessageBox.Show("驾照不存在，无法添加罚单");
                    }
                    else
                    {
                        Ticket t1 = new Ticket()
                        {
                            CODE = int.Parse(FDTJcomboBox.Text),
                            TIME = FDTJdateTimePicker.Value,
                            PLACE = FDTJtextBox3.Text,
                            EXDATE = FDTJdateTimePicker.Value.AddMonths(6),
                            LICENSENUM = int.Parse(FDTJtextBox2.Text),
                            STATE = 0
                        };
                        DB.Ticket.InsertOnSubmit(t1);
                        License Lp = DB.License.Single(p => p.LICENSENUM.ToString().Equals(l1.LICENSENUM));
                        Illegal Ip = DB.Illegal.Single(p => p.CODE.ToString().Equals(t1.CODE));
                        Lp.MARKS -= Ip.DECMARKS;
                        DB.SubmitChanges();
                        MessageBox.Show("添加完成");
                    }
                }
            }
            else { MessageBox.Show("请填写完整"); }       
        }
        private void FDTJcomboBox_TextChanged(object sender, EventArgs e)//罚单管理---罚单添加--违章代码显示
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            Illegal ill = DB.Illegal.SingleOrDefault(p => p.CODE.ToString().Equals(FDTJcomboBox.Text));
            if (ill != null) { FDTJtextBox1.Text = ill.CONTENTS; }
        }
        private void FDXGbutton_Click(object sender, EventArgs e)//罚单管理---罚单修改
        {
            ReVisible(sender, e, 7);
            panel7.Visible = true;
            var Tid = dataGridView5.SelectedRows[0].Cells[0].Value.ToString();
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var Tp = DB.Ticket.Single(p => p.ID.ToString().Equals(Tid));
            var result = from T in DB.Ticket
                         join I in DB.Illegal on T.CODE equals I.CODE
                         join L in DB.License on T.LICENSENUM equals L.LICENSENUM 
                         where T.ID.ToString().Equals(Tid)
                         select new
                         {
                             罚单编号 = T.ID,
                             违章代码 = T.CODE,
                             违章内容 = I.CONTENTS,
                             违章时间 = T.TIME,
                             违章地点 = T.PLACE,
                             缴费期限 = T.EXDATE,
                             缴费情况 = T.STATE == 1 ? "已缴费" : "未缴费",
                             驾照编号 = T.LICENSENUM,
                             姓名 = L.NAME
                         };
            dataGridView6.DataSource = result;
            FDXGcomboBox.Text = Tp.CODE.ToString();
            FDXGtextBox1.Text = Tp.LICENSENUM.ToString();
            FDXGtextBox2.Text = Tp.PLACE;
            FDXGtextBox4.Text = Tp.STATE.ToString();
            FDXGdateTimePicker.Value = Tp.TIME;
        }
        private void FDXGbutton1_Click(object sender, EventArgs e)//罚单管理---罚单修改--修改操作
        {

            var Tid = dataGridView6.SelectedRows[0].Cells[0].Value.ToString();
            DataClasses1DataContext DB = new DataClasses1DataContext();          var Tp = DB.Ticket.Single(p => p.ID.ToString().Equals(Tid));
            DialogResult dr = MessageBox.Show("确定要修改吗？", "取消", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                Tp.CODE = int.Parse(FDXGcomboBox.Text);
                Tp.LICENSENUM = int.Parse(FDXGtextBox1.Text);
                Tp.PLACE = FDXGtextBox2.Text;
                Tp.TIME = FDXGdateTimePicker.Value;
                Tp.STATE = int.Parse(FDXGtextBox4.Text);
                DB.SubmitChanges();
                MessageBox.Show("修改完成");
                FDXGbutton_Click(sender, e);
            }
        }
        private void dataGridView5_CurrentCellChanged(object sender, EventArgs e)//罚单管理---修改按钮激活
        {
            if (dataGridView5.CurrentCell != null)
            {
                FDXGbutton.Enabled = true;
            }
        }
        private void FDXGcomboBox_TextChanged(object sender, EventArgs e)//罚单管理---罚单修改--违章代码显示
        {
            DataClasses1DataContext DB = new DataClasses1DataContext();
            Illegal ill = DB.Illegal.SingleOrDefault(p => p.CODE.ToString().Equals(FDXGcomboBox.Text));
            if (ill != null) { FDXGtextBox3.Text = ill.CONTENTS; }
        }
        private void FDXGbutton2_Click(object sender, EventArgs e)//罚单管理---罚单修改--重置按钮
        {
            FDXGbutton_Click(sender, e);
        }
        private void ReButton_Click(object sender, EventArgs e)//事务办理---注册审核
        {
            ReVisible(sender, e, 9);
            panel9.Visible = true;
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var result = from U in DB.Users
                         where U.STATE == 0
                         select new
                         {
                             账号编号 = U.ID,
                             账号用户名 = U.USERNAME,
                             用户姓名 = U.NAME,
                             身份证 = U.IDNUM,
                             驾照编号 = U.LICENSENUM,
                             审核情况 = U.STATE == 1 ? "已激活" : "未激活"
                         };
            dataGridView8.DataSource = result;
        }
        private void ZCSHbutton_Click(object sender, EventArgs e)//事务办理---注册审核--审核通过
        {
            var Uid = dataGridView8.SelectedRows[0].Cells[0].Value.ToString();
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var Up = DB.Users.Single(p=>p.ID.ToString().Equals(Uid));
            DialogResult dr = MessageBox.Show("确定审核通过？", "审核确定", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                Up.STATE = 1;
                DB.SubmitChanges();
                MessageBox.Show("审核通过，账号已激活");
                ReButton_Click(sender, e);
            }
            else { ReButton_Click(sender, e); }
        }
        private void BBButton_Click(object sender, EventArgs e)//事务处理---补办审核
        {
            ReVisible(sender, e, 10);
            panel10.Visible = true;
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var result = from L in DB.License
                         join U in DB.Users on L.LICENSENUM equals U.LICENSENUM 
                         where L.STATE == 0
                         select new
                         {
                             驾照编号 = L.LICENSENUM,
                             用户姓名 = L.NAME,
                             驾照类型 = L.TYPE,
                             初次领证日期 = L.FIRSTDATE,
                             驾照到期日 = L.EXDATE,
                             扣分详情 = L.MARKS,
                             身份证 = U.IDNUM,
                         };
            dataGridView9.DataSource = result;
        }
        private void BBSHbutton_Click(object sender, EventArgs e)//事务处理---补办审核--审核通过
        {
            var Lid = dataGridView9.SelectedRows[0].Cells[0].Value.ToString();
            DataClasses1DataContext DB = new DataClasses1DataContext();
            var Lp = DB.License.Single(p => p.LICENSENUM.ToString().Equals(Lid));
            Applications Ap = DB.Applications.Single(p=>p.LICENSENUM.ToString().Equals(Lid));
            DialogResult dr = MessageBox.Show("确定审核通过？", "审核确定", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                Lp.STATE = 1;
                DB.Applications.DeleteOnSubmit(Ap);
                DB.SubmitChanges();
                MessageBox.Show("审核通过，驾照已补办成功");
                BBButton_Click(sender, e);
            }
            else { BBButton_Click(sender, e); }
        }
    }
}
